<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职工号" prop="jobNumber">
        <el-input
          v-model="queryParams.jobNumber"
          placeholder="请输入职工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" filterable  placeholder="请选择">
          <el-option v-for="item in statusList"
                     :key="item.statusCode"
                     :label="item.statusName"
                     :value="item.statusCode"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="转出工会" prop="outDeptId">
        <el-select v-model="queryParams.outDeptId" filterable  placeholder="请选择">
          <el-option v-for="item in deptList"
                     :key="item.deptId"
                     :label="item.deptName"
                     :value="item.deptId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="转入工会" prop="intoDeptId">
        <el-select v-model="queryParams.intoDeptId" filterable  placeholder="请选择">
          <el-option v-for="item in deptList"
                     :key="item.deptId"
                     :label="item.deptName"
                     :value="item.deptId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:appTransfer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:appTransfer:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:appTransfer:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:appTransfer:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="appTransferList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="姓名" align="center" prop="params.realName" />
      <el-table-column label="职工号" align="center" prop="params.jobNumber" />
      <el-table-column label="转出工会" align="center" prop="params.deptNameOut" />
      <el-table-column label="转入工会" align="center" prop="params.deptNameInto" />
      <el-table-column label="审核状态" align="center" prop="params.statusName" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="auditInto(scope.row)"
            v-hasPermi="['business:appTransfer:auditInto']"
            :disabled="scope.row.status !='2'"
          >审核</el-button>
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:appTransfer:remove']"
          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改转会申请记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form"  label-width="80px">
        <el-form-item label="审核状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio label="3">通过</el-radio>
            <el-radio label="4">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="remark">
          <el-input v-model.trim="form.opinion" type="textarea" :rows="4" placeholder="请输入审核意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listAppTransferInto, getAppTransfer, delAppTransfer, addAppTransfer, updateAppTransfer,auditInto } from "@/api/approval/appTransfer";
  import { selectSecondDeptList } from "@/api/system/dept";
  export default {
    name: "AppTransfer",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 转会申请记录表格数据
        appTransferList: [],
        deptList:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          outDeptId: null,
          intoDeptId: null,
          status: null,
          beginTime:null,
          endTime:null,
        },
        // 表单参数
        form: {
          id: null,
          status: null,
          opinion: null
        },
        statusList:[
          {"statusCode":"0","statusName":"待转出工会审核"},
          {"statusCode":"1","statusName":"转出工会审核驳回"},
          {"statusCode":"2","statusName":"待转入工会审核"},
          {"statusCode":"3","statusName":"转入工会审核通过"},
          {"statusCode":"4","statusName":"转入工会审核驳回"},
        ],
        // 表单校验
        rules: {
          miniUserId: [
            { required: true, message: "小程序用户ID不能为空", trigger: "blur" }
          ],
          deptId: [
            { required: true, message: "转入工会不能为空", trigger: "blur" }
          ],
          status: [
            { required: true, message: "审核状态", trigger: "blur" }
          ],
        }
      };
    },
      created() {
        this.getList();
        this.selectSecondDeptList();
      },
      methods: {
        /** 查询转会申请记录列表 */
        getList() {
          this.loading = true;
          if(this.dateRange !=null) {
            this.queryParams.beginTime = this.dateRange[0];
            this.queryParams.endTime = this.dateRange[1];
          }else {
            this.queryParams.beginTime = null;
            this.queryParams.endTime = null;
          }
          listAppTransferInto(this.queryParams).then(response => {
            this.appTransferList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
        },
        selectSecondDeptList() {
          selectSecondDeptList().then(response => {
            this.deptList = response.data;
          });
        },
        // 取消按钮
        cancel() {
          this.open = false;
          this.reset();
        },
        // 表单重置
        reset() {
          this.form = {
            id: null,
            status: "3",
            opinion: null
          };
          this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.dateRange = [];
          this.resetForm("queryForm");
          this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
          this.ids = selection.map(item => item.id)
          this.single = selection.length!==1
          this.multiple = !selection.length
        },
        /** 审核 */
        auditInto(row) {
          this.reset();
          this.open = true;
          this.title = "审核";
          this.form.id=row.id;
        },
        /** 提交按钮 */
        submitForm() {
          if(this.form.status=='4' && (this.form.opinion ==""|| this.form.opinion ==null)){
            this.$modal.msgWarning("审核意见不能为空");
            return false;
          }
          auditInto(this.form).then(response => {
                this.$modal.msgSuccess("操作成功");
                this.open = false;
                this.getList();
              });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
          const ids = row.id || this.ids;
          this.$modal.confirm('是否确认删除转会申请记录编号为"' + ids + '"的数据项？').then(function() {
            return delAppTransfer(ids);
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {});
        },
        /** 导出按钮操作 */
        handleExport() {
          this.download('business/appTransfer/export', {
            ...this.queryParams
          }, `appTransfer_${new Date().getTime()}.xlsx`)
        }
      }
    };
</script>
